﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace mozhi.smarterp.Finance.Basedatas
{
    public class DataAssociation : AggregateRootBase<Guid>
    {
        /// <summary>
        /// 占有者
        /// </summary>
        public Guid OccupantId { set; get; }

        /// <summary>
        /// 占有者类型
        /// </summary>
        public string OccupantType { set; get; }

        /// <summary>
        /// 占有者类型名称
        /// </summary>
        public string OccupantTypeName { set; get; }

        /// <summary>
        /// 占有者编码
        /// </summary>
        public string OccupantCode { set; get; }

        /// <summary>
        /// 占有者名称
        /// </summary>
        public string OccupantName { set; get; }

        /// <summary>
        /// 被占有者
        /// </summary>
        public Guid OccupiedId { set; get; }


        /// <summary>
        /// 被占有者类型
        /// </summary>
        public string OccupiedType { set; get; }


        /// <summary>
        /// 被占有者类型名称
        /// </summary>
        public string OccupiedTypeName { set; get; }

        /// <summary>
        /// 被占有者编码
        /// </summary>
        public string OccupiedCode { set; get; }

        /// <summary>
        /// 被占有者名称
        /// </summary>
        public string OccupiedName { set; get; }


        public DataAssociation(Guid id, Guid occupantId,  string occupantType, string occupantTypeName,string occupantCode, string occupantName , 
            Guid occupiedId , string occupiedType , string occupiedTypeName , string occupiedCode, string occupiedName)
        {
            Id = id;
            OccupantId = occupantId;
            OccupantType = occupantType;
            OccupantTypeName = occupantTypeName;
            OccupantCode = occupantCode;
            OccupantName = occupantName;
            OccupiedId = occupiedId;
            OccupiedType = occupiedType;
            OccupiedTypeName = occupiedTypeName;
            OccupiedCode = occupiedCode;
            OccupiedName = occupiedName;

            Validate();
        }

        public void ChangeOccupied(Guid occupiedId, string occupiedType, string occupiedTypeName, string occupiedCode, string occupiedName)
        {
            OccupiedId = occupiedId;
            OccupiedType = occupiedType;
            OccupiedTypeName = occupiedTypeName;
            OccupiedCode = occupiedCode;
            OccupiedName = occupiedName;

            Validate();
        }


        private void Validate()
        {
            if(OccupantId==default)
                throw new ArgumentNullException(nameof(OccupantId));

            if(OccupantType.IsNullOrEmpty())
                throw new ArgumentNullException (nameof(OccupiedType));

           if(OccupiedId==default)
                throw new ArgumentNullException(nameof (OccupiedId));

           if(OccupiedType.IsNullOrEmpty())
                throw new ArgumentNullException(nameof(OccupiedType));
        }

    }
}
